package com.huluobo.kotlinim2006a.db

import android.content.Context
import android.database.sqlite.SQLiteDatabase
import com.huluobo.kotlinim2006a.IMApplication
import org.jetbrains.anko.db.*

/**
 * Created by lc on 2023/2/7.
 */
class DatabaseHelper(context: Context = IMApplication.instance) : ManagedSQLiteOpenHelper(
    context, NAME, null, VERSION
) {
    companion object {
        const val NAME = "im.db"
        const val VERSION = 1
    }

    override fun onCreate(db: SQLiteDatabase?) {
        db?.createTable(
            ContactTable.NAME,//数据库的表名
            true,//代表如果不存在就创建一个该表,如果传false代表如果当前表不存在也不创建
            ContactTable.ID to INTEGER + PRIMARY_KEY + AUTOINCREMENT,//to 代表给当前字段添加属性,类似于Java中键值对:,int类型,主键,自增
            ContactTable.CONTACT to TEXT,
        )
    }

    override fun onUpgrade(db: SQLiteDatabase?, oldVersion: Int, newVersion: Int) {
        db?.dropTable(ContactTable.NAME, true)
        onCreate(db)
    }
}